#!/bin/bash

set -e
set -x

pushd rust

declare -ar args=(
--prefix="/home/zazdxscf/build/1nonpkgs/rust/usr/local"
#--disable-rpath
--enable-rpath #so that you don't have to prefix the rustc exe with LD_LIBRARY_PATH to avoid failure to load its .so libs
#--disable-verify-install #nolonger exists
--enable-manage-submodules

--disable-clang
#--enable-clang

--enable-ccache
--enable-dist-host-only
--disable-valgrind
--disable-helgrind
--disable-valgrind-rpass
--python="/usr/bin/python2"

#--disable-optimize
#--disable-optimize-cxx
--enable-optimize
--enable-optimize-cxx
--enable-optimize-llvm  #I didn't test the disable one here!
#--disable-optimize-llvm  #disable this so llvm has debug symbols! FIXME: find a way to keep optimize too!  XXX: DON'T EVER USE THIS! it will take at least half-aday to compile! especially stage2! (still compiling now, started: 2015/10/25 21:13:27 , now is: 2015/10/26 09:05:39  (but I've had cpu governor conservative for a long time, which kept cpu at 800Mhz(lowest) even though rustc was using 100% cpu, but was only 1 rustc.)  switched to ondemand gov. for the past 4 hours, which keeps it at max.  (took 974min! of which 10min were tests which failed)

--disable-debug
#--enable-debug #//fail: https://github.com/rust-lang/rust/issues/28947 ACTUALLY this issue still happens even without --enable-debug(and with --disable-debug!) because --enable-debug implies --enable-debuginfo and the latter was also manually specified below.
--disable-debuginfo #this doesn't cause that issue:
#--enable-debuginfo #yep this one causes that issue: https://github.com/rust-lang/rust/issues/28947 in other words, this: ./configure --disable-debug --enable-debuginfo --enable-optimize --llvm-root=/usr && make -j1 -- all NO_REBUILD=1 TIME_PASSES=1 TIME_LLVM_PASSES=1 'RUSTFLAGS=--verbose -Z verbose -Z print-link-args -Z debug-llvm '   got fixed
--disable-debug-assertions
#--enable-debug-assertions
--disable-debuginfo-tests
#--enable-debuginfo-tests
#--enable-llvm-assertions
--disable-llvm-assertions
--disable-debug-jemalloc
#--enable-debug-jemalloc

--disable-local-rust
#--enable-local-rust
#--local-rust-root="/home/zazdxscf/build/1nonpkgs/rust/tmp_stage0/x86_64-unknown-linux-gnu" #this is a stage0 compiled(not the static one from bin! that's the downloaded one) it's the one from /home/zazdxscf/build/1nonpkgs/rust/rust/x86_64-unknown-linux-gnu/stage0/lib/rustlib/ which has this folder there: x86_64-unknown-linux-gnu/  that I moved into /tmp/1/
#^ with /usr it fails with not finding crate for std - so can't readily use the gentoo-installed rust
#--enable-fast-make

#--disable-llvm-version-check
#--llvm-root=/usr  #will fail in make (at some Bool step of what seems to be a configure step) this might fix it: https://github.com/rust-lang/rust/pull/29272  i need to test!



#--disable-libcpp
#--disable-jemalloc
--release-channel=dev

#without one or more of the following you get rustc trying to build for powerpc too for example (and others)
--host=x86_64-unknown-linux-gnu
--target=x86_64-unknown-linux-gnu
--build=x86_64-unknown-linux-gnu
#TODO: update these ^  and see more configure --help  when trying to rebuild rust for android, also see: 
#https://github.com/rust-lang/rust-wiki-backup/blob/master/Doc-building-for-android.md
#https://ghotiphud.github.io/rust/android/cross-compiling/2016/01/06/compiling-rust-to-android.html
#https://github.com/tomaka/android-rs-glue

)


time ./configure "${args[@]}"

set +x
#make docs NO_REBUILD=1

popd

echo "!! Done."

